package cn.edu.qut.edusys.controller;

import cn.edu.qut.edusys.mapper.UserMapper;
import cn.edu.qut.edusys.mapper.teacherMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teacher")
public class teacherController {
    @Resource
    private teacherMapper teachermapper;

    @RequestMapping("/reg")
    public int reg(String[] ids) {
        int row = 0;
        System.out.println(Arrays.toString(ids));
        for(int i=0;i<ids.length;i++){
            String t=ids[i];
            String[] tm=t.split("\\|");
            row+=teachermapper.save(tm[0],tm[1],tm[2],tm[3]);
        }
       // row = teachermapper.save(param);
        return row;
    }
    @RequestMapping("/update")
    public int update(String[] ids) {
        int row = 0;
        for(int i=0;i<ids.length;i++){
            String t=ids[i];
            String[] tm=t.split("\\~");
            System.out.println(tm);
            row+=teachermapper.update1(tm[0],tm[1]);
        }
        // row = teachermapper.save(param);
        return row;
    }

    @RequestMapping("/change")
    public int change(@RequestParam Map<String,String> param){
        int list;
        System.out.println(param);
        list=teachermapper.change(param);
        return list;
    }

    @RequestMapping("/search")
    public List<Map<String, Object>> search(@RequestParam Map<String, String> param) {
        List<Map<String, Object>> list = null;
        list = teachermapper.search(param);
        return list;
    }

    @RequestMapping("/search2")
    public List<Map<String, Object>> search2(@RequestParam Map<String, String> param) {
        List<Map<String, Object>> list = null;
        list = teachermapper.search2(param);
        return list;
    }

    @RequestMapping("/search3")
    public List<Map<String, Object>> search3(@RequestParam Map<String, String> param) {
        List<Map<String, Object>> list = null;
        list = teachermapper.search3(param);
        return list;
    }

    @RequestMapping("/search4")
    public List<Map<String,Object>> search4(String param) {
        System.out.println(param);
        return teachermapper.search4(param);
    }


}
